from levin.baseSystem import BaseClass

## def _(a):
##     return a

colors = [  _(u"Red") ,
            _(u"White") ,
            _(u"Pink") ,
            _(u"Sparkling") ,                         
            ]
import datetime
class BottleBase(BaseClass):
    country =  None
    region  =  None
    groupAppellation =  None    
    appellation =  None    
    cru_name =  "" #None
    color   =  None
    millesime= None
    volume= None
    meanrate =  None
    alcohol  =  None
    productor =  None
    numInStock =  None
    pricePerBottle =  None
    acquireDate =  None
    acquireComment =  None
    cepage =  None
    geolocalisation =  None
    otherInfo =  None

    suggestedFrom  =  None
    suggestedTo    =  None

    optimalMax =  None
    optimalMin =  None

    tastings = None

    bottleId = 0
    lastUpdate = datetime.datetime.min

    removedTastings = []


BottleBase._wineAttributes = [k for k in BottleBase.__dict__.keys() if not k.startswith('_') ]

WineObjectTranslation = {
    "country"       : _("Country"),
    "region"        : _("Region"),
    "appellation"   : _("Appellation"),
    "cepage"	    : _("Cepage"),
    "cru_name"	    : _("Cru Name"),
    "millesime"     : _("Vintage"),
    "volume"        : _("Volume"),
    "alcohol"       : _("Alcohol"),
    "productor" 	: _("Productor"),
    "numInStock" 	: _("Bottles in cellar"),
    "pricePerBottle" 	: _("Bottle price"),
    "acquireDate" 	    : _("Acquisition date"),
    "acquireComment"	: _("Acquisition comment"),
    "geolocalisation"	: _("Geo localisation"),
    "otherInfo"	    : _("Comments"),

    "suggestedFrom"	: _("Suggested by"),
    "suggestedTo"	: _("Suggested to"),

    "optimalMin"	: _("Optimal start"),
    "optimalMax"	: _("Optimal end"),
    "color"         : _("Color"),
    "rate"          : _("Rate"),
    "meanrate"      : _("Rate"),
    "date"          : _("Date"),

    #tastings
    "comment" : _("Comments"),
    "numTastings" : _("Number of tastings")
}    


class Tasting(object):

    date = None
    rate = None

    bottle = None

    tastingId = 0
    

    def toDict(self):
        l = []
        for att, t in wineTasting.OrderedTastingAtt.iterAll():
            v = getattr(self, att)
            if v is not None:
                l.append(v)
        return v

    def fromDict(self, l):
        for a,v in l:
            setattr(self,a,v)

    def __getstate__(self):
        d = dict(self.__dict__)
        d.pop('bottle',None)
        return d

    def compare(self,o):
        #ok = True
        for att, t in wineTasting.OrderedTastingAtt.iterAll():
            if getattr(self,att) != getattr(o,att):
                return False
        return (o.rate == self.rate) and ( o.date == self.date)

    def differing_att(self,o):
        dif = [att for att, t in wineTasting.OrderedTastingAtt.iterAll() if getattr(self,att) != getattr(o,att) ]
        if (o.rate != self.rate) : dif +=['rate']
        if ( o.date != self.date) : dif += ['date']
        return dif
    
import wineTasting
for att_n, att_t in wineTasting.OrderedTastingAtt.iterAll():
    setattr(Tasting, att_n, None)

